import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/** 
 * @author Team Name: ByteCode
 * Team members: Kevin Conner, Vinesh Thakur, and James Yu
 *  MancalaPlayerPanel class  contains the on undo button
 */
public class MancalaUndoPanel extends JPanel{
   private String tmp;
   private JTextField player;
   private MancalaDataModel data;
   private JButton undo = null;

   /**
    * MancalaPlayerPanel constructor initializes values
    * @param name of player
    * @param mdm data model of the game
    */
   public MancalaUndoPanel(String name, MancalaDataModel mdm){
      super();
      data = mdm;
      tmp = name;
      player = new JTextField(tmp);


      this.add(player);
      player.setEditable(false);
      undo = new JButton("Undo");
      String string = "Undo";
      undo.setText(string);
      undo.addActionListener(new ActionListener()
      {
         public void actionPerformed(ActionEvent e)
         {
            data.undo();
         }
      });
      mdm.attach(new
            ChangeListener()
      {@Override
         public void stateChanged(ChangeEvent e) {
         repaint();         
      }});
      this.add(undo);
   }

   /**
    * paintComponent draws the panel 
    */
   public void paintComponent(Graphics g){
      super.paintComponent(g);
   }

}
